package com.group.prescription.controller;

import com.group.commons.util.CommonStatus;
import com.group.commons.util.ResponseInfo;

import com.group.prescription.entity.Prescription;
import com.group.prescription.service.iml.PrescriptionImpl;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("prescriptionCenter")
public class PrescriptionController {
    @Resource
    PrescriptionImpl PrescriptionService;
    @DeleteMapping("/prescription/{id}")
    @ApiOperation(value = "根据处方id删除单个处方", httpMethod = "DELETE")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", paramType = "int"),
    })
    public ResponseInfo deleteOne(@PathVariable  int id){

        return PrescriptionService.deleteOne(id);
    }

    @DeleteMapping("/prescriptions/{ids}")
    @ApiOperation(value = "批量删除处方", httpMethod = "DELETE")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", paramType = "List"),
    })
    public ResponseInfo batchDeletes(@PathVariable String ids){

        List<String> delList = new ArrayList<>();
        String[] strs = ids.split(",");
        for (String str: strs) {
            delList.add(str);
        }
        return PrescriptionService.batchDeletes(delList);
    }
    @PostMapping("/prescription/{page}/{pages}")
    @ApiOperation(value = "查询所有处方", httpMethod = "Post")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "prescription", paramType = "Prescription"),
    })
    public ResponseInfo findAll(@RequestBody Prescription prescription, @PathVariable int page, @PathVariable int pages) {

        return PrescriptionService.findAll(prescription, page, pages);
    }
    @PostMapping("/prescriptionS/{page}/{pages}/{commonStatus}")
    @ApiOperation(value = "根据审核状态查询处方", httpMethod = "Post")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commonStatus", paramType = "int"),
    })
    public ResponseInfo findByStatus( @PathVariable("page") int page, @PathVariable("pages") int pages,@PathVariable("commonStatus") int commonStatus) {
        CommonStatus c=CommonStatus.FAIL;
        switch (commonStatus){
            case 0:
            c=CommonStatus.FAIL;
            break;
            case 1:
            c=CommonStatus.AUDIT;
            break;
            case 2:
            c=CommonStatus.PASS;

        }
        return PrescriptionService.findByStatus(c, page, pages);
    }

}
